﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace QLBenhVien
{
    public class DBOUser
    {
        public int id { get; set; }
        public string username { get; set; }
        public string password { get; set; }
        //1:admin 2:bac si 3:thuoc 4:thu ngan 5:tiep tan
        public User_Type usertype { get; set; }
        public string fullname { get; set; }
        public enum User_Type
        {
            Admin = 1,BacSi = 2, Thuoc = 3, ThuNgan = 4, TiepTan = 5, XetNghiem = 6
        }

        public DBOUser()
        {
        }

        public DBOUser(string username, string password)
        {
            this.username = username;
            this.password = password;
        }

        public DBOUser isValid()
        {
            DataTable dt = DAOUser.getUser(username, password);
            if (dt.Rows.Count > 0)
            {
                this.id = (int)dt.Rows[0]["id"];
                this.usertype = (DBOUser.User_Type)dt.Rows[0]["usertype"];
                this.username = dt.Rows[0]["username"].ToString();
                this.fullname = dt.Rows[0]["fullname"].ToString();
                return this;
            }
            else
            {
                return null;
            }
        }
    }
}
